<?php

	class AppController extends Controller
	{
		var $components = array('Session',
		'Auth' => array(
		    	'loginAction' => array(
		        'controller'    => 'm_users',
		        'action'        => 'login'
				),
		    	'authError' => 'You have to login first',
		    	'loginError' => 'Your username or password was wrong',
			)
		);
	
		// Before Render
		function beforeRender() {
			if($this->name == 'CakeError') {
				//$this->layout = 'error';
			}
		}
		
		function beforeFilter() {
			Security::setHash("md5");
			$this->Auth->allow('login');
			$this->Auth->userModel = 'MUser';
			$this->Auth->fields = array('username' => 'user_id','password' => 'password');
			$this->Auth->userScope = array('MUser.invalid_flg' => 0);
			$this->layout = 'main_UI';
			
			$this->set("Usersuser_name",$this->Usersuser_name());
			$this->set("UsersID",$this->UsersID());
		}
		
		function Usersuser_name(){
			$user_name = NULL;
			if($this->Auth->user())
			$user_name = $this->Auth->user("user_name");
			return $user_name;
		}
		function UsersID (){
			$id = NULL;
			if($this->Auth->user())
			$id = $this->Auth->user("id");
			return $id;
		}

	};
?>
